HOW TO USE THE ROM BIOS INTERRUPTS by Scott Pakin Introductory Notes: 1) It is assumed that the reader knows a little bit of assembly language programming. 2) These charts were taken from the ROM BIOS listing in the Technical Reference Manual. 3) All interrupts and function numbers are given in HEXADECIMAL (base 16)!!! SEND ALL QUESTIONS AND COMMENTS TO: Scott Pakin 6007 N. Sheridan Rd. Chicago, IL 60660 INTERRUPT 10 -- Display (VIDEO) I/O (AH) Operation Also on entry On return ------------------------------------------------------------------------------ 0 Set video mode (AL) = 0 40x25 B/W = 1 40x25 Color = 2 80x25 B/W = 3 80x25 Color = 4 320x200 Color = 5 320x200 B/W = 6 640x200 B/W 1 Set cursor type CH bits 0-4 = Start line CL bits 0-4 = End line [Other bits must be zero or problems may occur] 2 Position cursor (DH,DL) = Row, Column (BH) = Page number 3 Read cursor pos. (BH) = Page number (DH,DL) = Row, Column (CH,CL) = Cursor type 4 Read light pen pos. (AH) = 1 (DH,DL) = Row, Column for characters (CH,BX) = Row, Column for pixels [ If (AH) = 0, then the light pen switch is not down/triggered] 5 Select display page (AL) = New page value [ Valid only in text modes. ] [ (AL) must be 0-7 for 40-column and 0-3 for 80-column modes.] 6 Scroll page up (AL) = No. of lines (CH,CL) = Upper left (R,C) (DH,DL) = Lower right (R,C) (BH) = Attribute to be used on bottom lines [ (AL) = 0 clears entire screen. ] INTERRUPT 10 -- Display (VIDEO) I/O (AH) Operation Also on entry On return ------------------------------------------------------------------------------ 7 Scroll page down Same as function #6 except (BH) is the attribute to be used on the bottom lines 8 Read attribute/ (BH) = Display page (AL) = Character read character at current (AH) = Attribute cursor position [ (AH) is invalid if in in graphics modes. ] 9 Write attribute/ (BH) = Display page character at current (BL) = Attribute (Text) cursor position = Char. color (Graphics) (CX) = No. of chars. to write (AL) = Char. to write A Write character (BH) = Display page only at current (CX) = No. of characters to cursor position write (AL) = Character to write B Set color palette (BH) = Palette color ID (0-127) (BL) = Color value to be used with the color ID C Write dot (DX,CX) = Row, Column (AL) = Color [ If (AH) > 127, the dot will be exclusive-or'd with the dot presently occupying the dot position. ] D Read dot (DX,CX) = Row, Column (AL) = Color of dot read E Teletype output (AL) = Character to write (BL) = Foreground color (BH) = Display page [ (BL) is only valid in text modes. ] INTERRUPT 10 -- Display (VIDEO) I/O (AH) Operation Also on entry On return ------------------------------------------------------------------------------ F Read video mode (AL) = 0 40x25 B/W = 1 40x25 Color = 2 80x25 B/W = 3 80x25 Color = 4 320x200 Color = 5 320x200 B/W = 6 640x200 B/W = 7 Monochrome (AH) = No. of char. columns on screen (BH) = Current display page ________________________________________________________________________________ Notes on interrupt 10: 1) Page numbers are invalid in graphics modes or when using the monochrome monitor. If a register requires a page number, set it to zero if it's invalid. 2) For (Row, Column), (0,0) is upper left. 3) Text modes are often called Alphanumeric (Alpha) modes; there is no difference between the two. 4) Palette 0 Palette 1 ------------------------------------- Color 1 | Green Cyan Color 2 | Red Magenta Color 3 | Brown/Yellow Grey/White [ Color 3 is dependant on the background color. ] Background Colors Color (dec.) (bin.) Black 0 0000 Blue 1 0001 Green 2 0010 Cyan 3 0011 Red 4 0100 Magenta 5 0101 Brown 6 0110 Light Grey 7 0111 Dark Gray 8 1000 Light Blue 9 1001 Light Green 10 1010 Light Cyan 11 1011 Light Red 12 1100 Light Magenta 13 1101 Yellow 14 1110 White 15 1111 INTERRUPT 13 -- Diskette I/O (AH) Operation Also on entry On return ------------------------------------------------------------------------------ 0 Reset diskette system 1 Read diskette status (AL) = Diskette status [ See note #1 for a diagram of this byte. ] 2 Read sectors into (AL) = Number of sectors Carry flag = 0 a buffer (CL) = Starting sector # (AL) = No. of (CH) = Track number (0-39) sectors read (DL) = Drive number [ If CF is 1, then (0=A, 1=B, 2=C, 3=D) the operation was (DH) = Head number (0 or 1) unsuccessful and (ES:BX) = Address of buffer (AH) = Diskette status ] 3 Write sectors from Same as function #2 Same as function #2 a buffer 4 Verify sectors Same as function #2, but Same as function #2 the buffer is not needed 5 Format a track (ES:BX) = Sector information (AL) does not return (DL) = Drive # any informatiom, (AL) = # of sectors to format otherwise, results are the same as in [ see note #2 for more function #2 information ] ________________________________________________________________________________ Notes on interrupt 13: 1) The diskette staus byte looks like this: 7 6 5 4 3 2 1 0 Bits 0 & 1 -- if 01, invalid command if 10, address mark (to locate sectors) was not found if 11, write protect prevented writing on disk Bit Meaning (if on) 2 Sector not found 3 Direct memory access overrun, or if bit 0 is on (1), illegal attempt to transfer data across a 64K boundry 4 Cyclical redundancy check detected a read error 5 Diskette controller chip returned an error 6 Seek operation to a track failed 7 Drive failed to respond (time-out error) 2) The formatting data in the extra segment is set up like this: Byte number Meaning 1 Track number (0-39) 2 Head number (0 or 1) 3 Sector number (1-8; 9 if DOS 2.xx) 4 Number of bytes for sector (0=128, 1=256, 2=512, 3=1024) Only full tracks may be formatted; not individual sectors. This means that the above data must appear eight (nine for DOS 2.00+) times -- 32 bytes total for an entire track. Remember to set (AL) to match the number of sectors to be formatted. INTERRUPT 14 -- Asyncronous Communications (RS-232) I/O (AH) Operation Also on entry On return ------------------------------------------------------------------------------ 0 Initialize (DX) = Communications (AX) = Status word communications port adapter (0 = COM1, 1 = COM2) [ See note #2 for more information ] (AL) = Parameters for initialization [ See note #1 for more information ] 1 Send a character (DX) = Communications If (AH) > 127, an error over the comm. line adapter occurred; low 15 bits of (AL) = Character to send (AX) have status word 2 Wait for character (DX) = Communications If (AH) is non-zero, an from comm. line adapter error occurred; (AX) has status word 3 Read status word (AX) = Status word [ See note #2 for more information ] ________________________________________________________________________________ Notes on interrupt 14: 1) The parameters for initializing the communications adapter are as follows: 7 6 5 4 3 2 1 0 Bits 0 & 1 = Word length; 10 = 7 bit bytes 11 = 8 bit bytes Bit 2 = Stopbits; 0 = 1 stopbit 1 = 2 stopbits Bits 3 & 4 = Parity; x0 = no parity 01 = odd parity 11 = even parity [x could be 1 or 0 ] Bits 5-7 = Speed; 000 = 110 bps 001 = 150 bps 010 = 300 bps 011 = 600 bps 100 = 1200 bps 101 = 2400 bps 110 = 4800 bps 111 = 9600 bps 2) The communications port status is returned in (AX): 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 (AH) = Line control status (AL) = MODEM status Bit Meaning (when on) 0 Delta clear-to-send 1 Delta data set ready 2 Trailing edge ring detected 3 Delta receive line signal detected 4 Clear-to-send signal 5 Data set (MODEM) ready 6 Ring indication 7 Line signal detected 8 Data ready 9 Overrun error 10 Parity error 11 Framing error 12 Break detected 13 Transmission holding-register empty 14 Transmission shift-register empty 15 Time out [ NOTE: Bits 15, 10, and 8 might be set incorrectly if you have a BIOS with a release date of 4/24/81 ] INTERRUPT 15 -- Cassete I/O (AH) Operation Also on entry On return ------------------------------------------------------------------------------ 0 Turn cassette motor on 1 Turn cassette motor off 2 Read one or more (CX) = Number of bytes (DX) = Number of bytes 256-byte blocks from to read read cassette into a (ES:BX) = Pointer to Carry flag = 0 if buffer buffer successful If unsuccessful, the carry flag = 1 and (AH) has the error code [ See note #1 for more information ] 3 Write one or more (CX) = Number of bytes (CX) = 0 256-byte blocks from to write (ES:BX) = Pointer to the a buffer to (ES:BX) = Pointer to buffer byte after the cassette last byte written ________________________________________________________________________________ Notes on interrupt 15: 1) Error returns for function #2: 7 6 5 4 3 2 1 0 Bit Meaning (when on) 0 Cyclical redundancy check failed 1 Data transactions were lost 2 No data was found All other bits have no purpose 2) ROM BIOS automatically waits for the cassette motor to reach neccessary speed, writes a leader, a syncronization bit and a syncronization byte. It then writes the data in your buffer and forces it to take up a multiple of 256 bytes by appending zeroes. Then a 16-bit number to be used for cyclical redundancy checks and a trailer are added to the end of the block. INTERRUPT 16 -- Keyboard I/O (AH) Operation Also on entry On return ------------------------------------------------------------------------------ 0 Wait for keypress (AL) = Character read (AH) = Scan code of character read (i.e. if it's Ctrl, Shift, Alt, or a combination) 1 Check for character Zero flag = 1 if buffer ready is empty Zero flag = 0 if buffer is not empty. Next char. is in (AL), scan code is in (AH) 2 Return shift status (AL) = Shift status [ See note #1 for more information ] ________________________________________________________________________________ Notes on interrupt 16: 1) The shift status byte returned by function #2 looks like this: 7 6 5 4 3 2 1 0 Bit Meaning (when on) 0 Right shift key depressed 1 Left shift key is depressed 2 Ctrl key depressed 3 Alt key depressed 4 Scroll Lock state is on 5 Num Lock state is on 6 Caps Lock state in on 7 Insert mode is on 2) The shift status byte is located at memory location 0040:0017, and is called KB_FLAG by IBM. At location 0040:0018 is KB_FLAG_1, which looks like the following: 7 6 5 4 3 2 1 0 Bit Meaning (when on) 3 Hold state (Ctrl-Num Lock) is on 4 The Scroll Lock key is depressed 5 The Num Lock key is depressed 6 The Caps Lock key is depressed 7 The Insert key is depressed [ Bits 0, 1, and 2 have no meaning ] INTERRUPT 17 -- Printer I/O (AH) Operation Also on entry On return ------------------------------------------------------------------------------ 0 Print a character (AL) = Character to be (AH) = Printer status printed byte (see note (DX) = Printer to use #1) (0=LPT1, 1=LPT2 2=LPT3) 1 Initialize printer (DX) = Printer to use (AH) = Printer status byte 2 Read printer status (DX) = Printer to use (AH) = Printer status byte byte ________________________________________________________________________________ Notes on interrupt 17: 1) The printer status byte looks like this: 7 6 5 4 3 2 1 0 Bit Meaning (when on) 0 Time out error 3 I/O error 4 Selected (off-line) 5 Out of paper 6 Acknowledge 7 Busy [ Bits 1 and 2 have no meaning ] INTERRUPT 1A -- Time-of-Day (AH) Operation Also on entry On return ------------------------------------------------------------------------------ 0 Read current clock (CX) = High 16 bits of setting count (DX) = Low 16 bits of count (AL) = 0 if the time was last read within 24 hours. Otherwise, (AL) = 1 1 Set the system (CX) = High 16 bits of count clock (DX) = Low 16 bits of count ________________________________________________________________________________ Notes on interrupt 1A: 1) The count is the amount of 0.05492 (65535/1193100) seconds that have passed since 12 a.m. on January 1, 1980. Upon booting/rebooting, the count becomes zero (12 a.m.) and the system date becomes January 1, 1980 (although these could differ if you have a real-time clock/calendar installed). 2) The count is incremented 18.205 times per second (or, in fractional form, 1193100/65536 times per second). 3) After CX and DX both reach 65535 (FFFF hex), they stop increasing. (You don't have to worry about this happening, though, unless you leave your computer on for seven years -- until the system date reaches December 31, 2099.) SOME INTERESTING INTERRUPTS THAT ONLY HAVE SINGLE FUNCTIONS INTERRUPT 5 -- PRINT SCREEN Interrupt 5 prints everything on your screen. It is normally activated when you press , although it can be called from an assembly language program with an INT 5 instruction. Interrupt 5 returns a status byte in memory location 0050:0000. If this byte is 0, the screen was successfully printed. If an error occurred during printing, this byte is FF (decimal 255). ________________________________________________________________________________ INTERRUPT 11 -- EQUIPMENT CHECK Interrupt 11 reads the word at location 0040:0010, which contains some information about the system's hardware (taken from the DIP switch settings), and returns it in AX. AX then looks like this: 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 Bit 1 -- If on, computer has diskettes. Otherwise, no diskettes. Bit 12 -- If on, computer has game I/O card. Otherwise, no game I/O card. Bits Meaning How to Read Bits ---- ------- ---------------- 2&3 Memory on system board 00 = 16K 01 = 32K 10 = 48K 11 = 64K 4&5 Original video mode 00 = None (could be a T.V. set) 01 = 40x25 B/W, (color/graphics monitor) 10 = 80x25 B/W, (color/graphics monitor) 11 = 80x25 B/W, (monochrome monitor) 6&7 Number of disk drives 00 = 1 (only valid if bit 1 01 = 2 is on) 10 = 3 11 = 4 or more 9&10 Number of RS-232 cards 00 = None (serial ports) 01 = 1 10 = 2 11 = 3 14&15 Number of printers 00 = None (parallel ports) 01 = 1 10 = 2 11 = 3 INTERRUPT 18 -- CASSETTE BASIC An INT 18H instruction causes the computer to enter cassette BASIC, which is the form of BASIC that you use if you don't have diskettes (or if you forget to close the disk drive door when you boot up). ________________________________________________________________________________ INTERRUPT 19 -- REBOOT When you press , an interrupt 19 is executed. When put in a program, an INT 19H will reboot the system. ________________________________________________________________________________ INTERRUPT 1B -- BREAK When you press , the computer executes an INT 1BH instruction, which just performs an IRET instruction and returns to DOS. The pointer to this interrupt could be changed if you want to implement your own handler. ________________________________________________________________________________ INTERRUPT 1C -- TIMER TICK 18.205 times per second, an INT 18H instruction is executed. Like interrupt 1B, this interrupt is only an IRET instruction. If you have a routine that needs to be called 18.205 times a second, this interrupt could be helpful. SEND ALL QUESTIONS AND COMMENTS TO: Scott Pakin 6007 N. Sheridan Rd. Chicago, IL 60660